package com.pen.algorithm.basics;

public class TreeNode<T> {
    public   T val;

    public   TreeNode<T> left;
    public   TreeNode<T> right;

    public TreeNode(T val) {
        this.val = val;
    }
    TreeNode() {
    }

    /**   增加左子节点 
     * addLeft:  
     * @param value
     * void  返回类型    
     */
    public void addLeft(T value){
        TreeNode<T> left = new TreeNode<T>(value);
        this.left = left;
    }
    /**
     * addRight: 增加右子节点 
     * @param value
     * void  返回类型    
     */
    public void addRight(T value){
        TreeNode<T> right = new TreeNode<T>(value);
        this.right = right;
    }
    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     * 重载equal方法
     */
    @Override
    public boolean equals(Object obj) {
        // TODO Auto-generated method stub  
        if(!(obj instanceof TreeNode)){
            return false;
        }
        return this.val.equals(((TreeNode<?>)obj).val);
    }
    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     * 重载hashCode方法
     */
    @Override
    public int hashCode() {
        // TODO Auto-generated method stub  
        return this.val.hashCode();
    }
    @Override
    public String toString(){
        return this.val ==null?"":this.val.toString();
    }

}
